// package/pages/cardDetail/cardDetail.js
const utils = require('../../../utils/util.js');
let myRequest = require('../../../common/script/myRequest.js');
let api = require('../../../common/script/api.js');
let wxbarcode = require('../../../utils/wxbarcode/index.js')
let login = require('../../../common/script/login');
const app = getApp();
Page({
  /**
   * 页面的初始数据
   */
  data: {
    hiddenLoading: true,
    memberData: {},
    code: "",
    // applyCard: true
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    const that = this;
    // that.getCardinfoData();
    let memberData = wx.getStorageSync('memberData')
    that.setData({
      memberData: memberData,
    })
    this.aginGetdata();
    // this.getIsShowApplyCard()
    this.timeOut = null;

  },
  // getIsShowApplyCard() {
  //   const that = this;
  //   myRequest.EasyHttp.post(api.reqUrls.isShowApplyCard).then(res => {
  //     if (res.data.status == 1) {
  //       that.setData({
  //         applyCard: res.data.result == 1 ? true : false
  //       })
  //     }
  //   })
  // },
  //解绑
  btn() {
    const that = this;
    wx.showModal({
      content: '是否解绑会员卡?',
      success(res) {
        if (res.confirm) {
          console.log('用户点击确定')
          let data = {
            token: wx.getStorageSync('token'),
          }
          wx.showLoading({
            title: '加载中...',
          })
          myRequest.EasyHttp.post(api.reqUrls.unbindmember, data).then(res => {
            wx.hideLoading();
            if (res.data.status == 1) {
              wx.showModal({
                content: res.data.msg,
                showCancel: false,
                success() {
                  //返回tab页面刷新数据
                  wx.setStorageSync('refresh', true)
                  //返回优惠券页面刷新数据
                  wx.setStorageSync('refreshCoupon', true)
                  wx.navigateBack()
                }
              })
            } else {
              wx.showModal({
                content: res.data.msg,
                showCancel: false,
                confirmText: '我知道了',
                confirmColor: '#ff5151',
                success(e) {}
              })
            }
          })
        } else if (res.cancel) {
          console.log('用户点击取消')
        }
      }
    })

  },
  // getCardinfoData() {
  //   const that = this;
  //   let data = {
  //     token: wx.getStorageSync('token'),
  //   }
  //   wx.showLoading({
  //     title: '加载中...',
  //   })
  //   myRequest.EasyHttp.post(api.reqUrls.membercardShow, data).then(res => {
  //     wx.hideLoading();
  //     if (res.data.status == 1) {
  //       that.setData({
  //         memberData: res.data.result.member_data,
  //       })
  //     } else {
  //       wx.showModal({
  //         content: res.data.msg,
  //         showCancel: false,
  //         confirmText: '我知道了',
  //         confirmColor: '#ff5151',
  //         success(e) {
  //           //返回tab页面刷新数据
  //           wx.setStorageSync('refresh', true)
  //           //返回优惠券页面刷新数据
  //           wx.setStorageSync('refreshCoupon', true)
  //           wx.navigateBack({
  //             delta: 1
  //           })
  //         }
  //       })
  //     }
  //   })

  // },

  aginGetdata(e) {
    const that = this;
    let data = {
      token: wx.getStorageSync('token'),
    }
    myRequest.EasyHttp.post(api.reqUrls.getCardNumberCode, data).then(res => {
      if (res.data.status == 1) {
        var data = res.data.result.card_number_code;
        setTimeout(() => {
          wxbarcode.barcode("barcode", data, 680, 150);
          wxbarcode.qrcode("qrcode", data, {
            codeSize: 480,
            color: "#000000",
            bgcolor: "#ffffff",
          });
          that.setData({
            code: data
          })
        }, 500)
      }
    })
  },


  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  // onShareAppMessage: function () {

  // }
})